﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MyEngineExercise.我的扩展
{
    /// <summary>
    /// 获取指定文件夹的所有指定文件
    /// </summary>
    public class GetSplFloderSplFiles
    {
        public GetSplFloderSplFiles()
        {
        }

        //每次用的时候记得首先将这个变为string.empty
        private static string result = "";

        /// <summary>
        /// 得某文件夹下所有的文件
        /// </summary>
        /// <param name="directory">文件夹路径</param>
        /// <param name="pattern">搜寻指类型，如"*.xls"</param>
        /// <returns></returns>
        public static string GetFiles(DirectoryInfo directory, string pattern)
        {
            if (directory.Exists || pattern.Trim() != string.Empty)
            {

                foreach (FileInfo info in directory.GetFiles(pattern))
                {
                    result = result + info.FullName.ToString() + ";";
                    //result = result + info.Name.ToString() + ";";
                }

                foreach (DirectoryInfo info in directory.GetDirectories())
                {
                    GetFiles(info, pattern);
                }
            }
            string returnString = result;
            return returnString;

        }
    }
}
